package com.ktjy.ktmall.dao.impl;

import com.ktjy.ktmall.dao.BaseDao;
import com.ktjy.ktmall.dao.MenuDao;
import com.ktjy.ktmall.entity.Menu;
import com.ktjy.ktmall.entity.User;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MenuDaoImp extends BaseDao implements MenuDao {
    @Override
    public List<Menu> getMenuListPage(Integer from, Integer pageSize) {
        List<Menu> list = new ArrayList<>();
        // 查询已上架的商品分页列表
        String sql = "select * from `t_menu` order by create_time desc limit ?,?";
        rs = super.executeQuery(sql, from, pageSize);
        try {
            while (rs.next()) {
                Menu a = new Menu(rs.getInt("ps_id"),
                        rs.getString("ps_name"),
                        rs.getInt("ps_pid"),
                        rs.getInt("ps_level"),
                        rs.getString("ps_api_path"),
                        rs.getInt("ps_api_order"),
                        rs.getString("ps_icon"),
                        rs.getInt("enabled"),
                        rs.getString("create_time"),
                        rs.getString("update_time")
                );
                list.add(a);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return list;
    }
}
